package com.controller;

import com.po.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class UserController {
    @RequestMapping("/login")
    public String Login(User user, Model model, HttpSession httpSession){
        String username=user.getUsername();
        String password=user.getPassword();
        if(username!=null && username.equals("admin")){
            if(password.equals("123") && password!=null){
                httpSession.setAttribute("user",user);
                return "main";
            }
        }
        model.addAttribute("msg","login error");
        return "login";
    }

    @RequestMapping("/tologin")
    public String toLogin(){
        return "login";
    }

    @RequestMapping("/main")
    public String toMain(){
        return "main";
    }

    @RequestMapping("/loginout")
    public String LoginOut(HttpSession httpSession){
        httpSession.invalidate();
        return "login";
    }

}
